home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
FLAT.ZIP
/
FLATFILE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-19
|
3KB
|
133 lines
#define WIN31
#include <windows.h>
/* For the fancy looking Borland dialog box routines */
#ifdef USES_BWCC
#include <bwcc.h>
#endif
#include "flatm.h"
#pragma hdrstop
#include <io.h>
#include "flatfile.h"
#include "flatdata.h"
#ifdef USES_MEMCHECK
/* Memory checking routines by StratosWare Corp. */
#include "\wmemchec\memcheck.h"
#endif
/*--------------------------------------------
-
- FLATFILE.C For Flat Windows Program
-
- Date file routines for Flat
-
- Dennis R. Fischer
- Denam Systems
- 1115 Madison St. NE Suite 226
- Salem, Oregon 97303
-
- CompuServe 70405,1422
- Internet 70405.1422@compuserve.com
-
- Developed with Borland 3.1 Compiler
-
- Free for the taking but please give credit
- where credit is do
-
----------------------------------------------*/
char flatfilename[] = {"flat.sav"};
long GetNumOfFlatRecords(void)
{
/* Get the total number of records in the data base */
long lTotRecs=0L;
long lFileSize;
HFILE fhand;
fhand = _lopen(flatfilename, OF_READ);
if (fhand != -1 ) {
/* File was found */
lFileSize = _llseek(fhand, 0L, SEEK_END);
if (lFileSize > 0L) {
lTotRecs = lFileSize / (long)sizeof(struct tagFLATDATA);
}
_lclose(fhand);
}
return lTotRecs;
}
BOOL readdatafile (long recnum)
{
/* Read one record in the data base */
BOOL bGood = FALSE;
HFILE fhand;
int recsize;
long result;
struct tagFLATDATA Flat;
recsize = sizeof(Flat);
fhand = _lopen(flatfilename, OF_READ);
if (fhand != -1 ) {
/* File was found */
result = _llseek(fhand, recnum * recsize, SEEK_SET);
if (result != -1L) {
if (_lread(fhand, (LPSTR)&Flat, (WORD)recsize) == recsize){
bGood = TRUE;
SetFlatData(&Flat);
}
}
_lclose(fhand);
}
return bGood;
} /* readdatafile */
BOOL savedatafile (long recnum)
{
/* Save a record in the data base */
HFILE fhand;
struct tagFLATDATA Flat;
long tl;
BOOL bGood = FALSE;
int recsize;
recsize = (WORD)sizeof(Flat);
fhand = _lopen(flatfilename, OF_READWRITE);
if (fhand != -1 ) {
/* File was found */
GetFlatData(&Flat);
tl = _llseek(fhand, recnum * recsize, 0);
if (tl != HFILE_ERROR){
_lwrite(fhand, (LPSTR)&Flat, recsize);
bGood = TRUE;
}
_lclose(fhand);
}
return bGood;
} /* savedatafile */
BOOL SaveNewSale (void)
{
/* Save a new record in the data base. Create the
data base file if needed
*/
HFILE fhand2;
BOOL bGood=FALSE;
struct tagFLATDATA Flat;
fhand2 = _lopen(flatfilename, OF_READWRITE);
if (fhand2 == -1)
/* Try to create it */
fhand2 = _lcreat(flatfilename, 0);
if (fhand2 != -1 ) {
/* File was found so move to end of file */
_llseek(fhand2, 0L, SEEK_END);
GetFlatData(&Flat);
Flat.Used = TRUE;
_lwrite(fhand2, &Flat, (UINT)sizeof(Flat));
_lclose(fhand2);
bGood = TRUE;
}
return bGood;
} /* SaveNewSale */